/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmRelatorio.java
 *
 * Created on 29/06/2011, 18:53:10
 */
package com.pedagio.view;

import com.pedagio.dominio.Atendimento;
import com.pedagio.dominio.FalhaSistema;
import com.pedagio.modelo.AtendimentoModelo;
import com.pedagio.modelo.FalhasModelo;
import com.pedagio.negocio.AtendimentoService;
import com.pedagio.negocio.FalhaSistemaService;
import com.pedagio.util.Controle;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author pedroo
 */
public class FrmRelatorio extends javax.swing.JDialog {
    
    private FalhaSistemaService falhaService = Controle.getFalhaService();
    private AtendimentoService atendimentoService = Controle.getAtendimentoService();
    
            

    /** Creates new form FrmRelatorio */
    public FrmRelatorio(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        popularRelatorios();
        
    }

    private void popularRelatorios() {
        
        FalhasModelo falhasModelo = new FalhasModelo();
        tblFalhas.setModel(falhasModelo);
        
        List<FalhaSistema> dispositivos = falhaService.findAll();
        for (FalhaSistema veiculo : dispositivos) {
           falhasModelo.addRow(veiculo);
        }
        
        
        AtendimentoModelo atendimentoModelo = new AtendimentoModelo();
        tblAtendimentos.setModel(atendimentoModelo);
        
        List<Atendimento> atendimentos = atendimentoService.findAll();
        for (Atendimento atendimento : atendimentos) {
           atendimentoModelo.addRow(atendimento);
        }
        
        
    }
    
    /** This method is called from within the constructor to
      * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        lblAviso = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblAtendimentos = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblFalhas = new javax.swing.JTable();
        lblAviso1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(242, 247, 247));

        lblAviso.setFont(new java.awt.Font("DejaVu Sans", 0, 14)); // NOI18N
        lblAviso.setText("Relatórios de Atendimentos");

        jScrollPane1.setViewportView(tblAtendimentos);

        jScrollPane3.setViewportView(tblFalhas);

        lblAviso1.setFont(new java.awt.Font("DejaVu Sans", 0, 14)); // NOI18N
        lblAviso1.setText("Relatório de Falhas");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lblAviso, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lblAviso1, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblAviso)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(lblAviso1)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                FrmRelatorio dialog = new FrmRelatorio(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel lblAviso;
    private javax.swing.JLabel lblAviso1;
    private javax.swing.JTable tblAtendimentos;
    private javax.swing.JTable tblFalhas;
    // End of variables declaration//GEN-END:variables
}
